package demo3lambda;

import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @Author 12629
 * @Description：
 */
/*@FunctionalInterface
interface TestInterFace {
    //注意：只能有一个方法
    void test();
    default void func() {

    }
    static void func3() {

    }
}*/









//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}
//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}

//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}
//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    double test(int a,double b);
}
public class Test {


    public static void main(String[] args) {
        Map<String,Integer> map = new HashMap<>();
        map.put("hello",1);
        map.put("abc",8);
        map.put("haha",4);
        map.put("pppp",2);

        map.forEach(new BiConsumer<String, Integer>() {
            @Override
            public void accept(String s, Integer integer) {
                System.out.println("key: "+s+" val: "+integer);
            }
        });
        System.out.println("=====");

        map.forEach((key,val)->{ System.out.println("key: "+key+" val: "+val);});
    }
    public static void main9(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("hello");
        list.add("abcd");
        list.add("world");
        list.add("feifie");

        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        System.out.println("========");
        list.forEach(s->System.out.println(s));
        System.out.println("====排序====");
       /* list.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        });*/
        list.sort((o1, o2) -> o1.compareTo(o2));
        list.forEach(s->System.out.println(s));
    }

    public static void main8(String[] args) {

        int a = 10;
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                //a = 99;
                System.out.println(a);
                return o1.compareTo(o2);
            }
        });


        PriorityQueue<Integer> priorityQueue2 = new PriorityQueue<>((o1,o2)->{return o1.compareTo(o2);});
        PriorityQueue<Integer> priorityQueue21 = new PriorityQueue<>((o1,o2)->o1.compareTo(o2));

        MoreParameterNoReturn moreParameterNoReturn = (int x,int y) -> {
            //a = 99;
            System.out.println(a);
            System.out.println(x+y);
        };
    }

    public static void main7(String[] args) {
        MoreParameterReturn moreParameterReturn = (x,y)->x+y;
        System.out.println(moreParameterReturn.test(1, 1.4));
    }

    public static void main6(String[] args) {
        OneParameterReturn oneParameterReturn = x -> x+10;
        System.out.println(oneParameterReturn.test(9));
    }

    public static void main5(String[] args) {
        //NoParameterReturn noParameterReturn = () -> {return 10;};
        NoParameterReturn noParameterReturn = () -> 10;
        System.out.println(noParameterReturn.test());
    }

    public static void main4(String[] args) {
        //MoreParameterNoReturn moreParameterNoReturn = (int x,int y) -> {System.out.println(x+y);};
        MoreParameterNoReturn moreParameterNoReturn = (x,y) -> System.out.println(x+y);
        moreParameterNoReturn.test(1,2);
    }

    public static void main3(String[] args) {
        //OneParameterNoReturn oneParameterNoReturn = (int x) -> { System.out.println(x+1);};
        OneParameterNoReturn oneParameterNoReturn =  x -> System.out.println(x+1);
        oneParameterNoReturn.test(10);
    }

    public static void main2(String[] args) {
        //NoParameterNoReturn noParameterNoReturn = ()->{System.out.println("test()...");};
        NoParameterNoReturn noParameterNoReturn = ()->System.out.println("test()...");
        noParameterNoReturn.test();
    }

    public static void main1(String[] args) {
        //相当于 一个匿名内部类  实现了接口 同时 重写了接口的方法
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("test()...");
            }
        };
        noParameterNoReturn.test();
    }
}
